<?php

use think\facade\Route;

//Api数据接口
Route::get('/swagger', function() {
    $openapi = \OpenApi\scan('../app/admin');
    header('Content-Type: application/json');
    echo $openapi->toJson();
});
//不需要登录验证
Route::rule('Index/login', 'admin/Index/login', 'post');
Route::rule('index', 'admin/Index/index', 'get');
Route::rule('Index/test', 'admin/Index/test', 'get');

//顶级菜单
Route::rule('/top-menu', 'admin/system', 'get')->generateMenu(['parent_route'=>'/', 'name' => 'system_setting', 'title' => '系统设置','icon'=>'md-options', 'hide'=>0, 'component'=>'Main', 'path' => '/system' ]);
Route::rule('/top-menu', 'admin/article', 'get')->generateMenu(['parent_route'=>'/', 'name' => 'admin_article', 'title' => '内容管理','icon'=>'ios-paper', 'hide'=>0, 'component'=>'Main', 'path' => '/articles']);
Route::rule('/top-menu', 'admin/user', 'get')->generateMenu(['parent_route'=>'/', 'name' => 'admin_user', 'title' => '用户管理', 'icon'=>'md-people','hide'=>0, 'component'=>'Main', 'path' => '/user']);

//需要登录验证
$result = Route::group(function () {
    Route::rule('Index/getRoute', 'admin/Index/getRoute', 'get');
    Route::rule('Profile/getUserInfo', 'admin/Profile/getUserInfo', 'get');
    Route::rule('Index/logout', 'admin/Index/logout', 'get');

    //附件组
    Route::group('Attachment', function () {
        Route::rule('index', 'admin/Attachment/index', 'get')->generateMenu([
            'parent_route'=>'admin/system', 'name'=>'attachments', 'title'=>'附件管理', 'path'=>'attachments',
            'component'=>'view/system/attachments.vue', 'auth'=>0, 'sort'=>0, 'hide'=>0, 'icon'=>'',
        ]);
        Route::group(function () {
            Route::rule('add', 'admin/Attachment/add', 'post')->generateMenu([ 'parent_route'=>'admin/Attachment/index', 'title'=>'附件添加' ]);
            Route::rule('editor', 'admin/Attachment/editor', 'post')->generateMenu([ 'parent_route'=>'admin/Attachment/index', 'title'=>'富文本编辑器上传文件' ]);
            Route::delete('delete/:id', 'admin/Attachment/delete')->generateMenu([ 'parent_route'=>'admin/Attachment/index', 'title'=>'附件删除' ]);
        })->middleware([\app\admin\middleware\AdminLog::class]);
    })->middleware([\app\admin\middleware\AdminPermission::class]);

    //客户端组
    Route::group('ClientVersion', function () {
        Route::rule('index', 'admin/ClientVersion/index', 'get')->generateMenu([
            'parent_route'=>'admin/system', 'name'=>'client_version', 'title'=>'版本管理', 'path'=>'client_version',
            'component'=>'view/system/client_version.vue', 'auth'=>0, 'sort'=>0, 'hide'=>0, 'icon'=>'',
        ])->middleware([\app\common\middleware\PreventConcurrent::class],10);
        Route::group(function () {
            Route::rule('add', 'admin/ClientVersion/add', 'post')->generateMenu([ 'parent_route'=>'admin/ClientVersion/index', 'title'=>'版本添加' ]);
            Route::put('changeStatus/:id', 'admin/ClientVersion/changeStatus')->generateMenu([ 'parent_route'=>'admin/ClientVersion/index', 'title'=>'更新状态' ]);
            Route::put('changeForce/:id', 'admin/ClientVersion/changeForce')->generateMenu([ 'parent_route'=>'admin/ClientVersion/index', 'title'=>'强制更新' ]);
            Route::delete('delete/:id', 'admin/ClientVersion/delete')->generateMenu([ 'parent_route'=>'admin/ClientVersion/index', 'title'=>'版本删除' ]);
        })->middleware([\app\admin\middleware\AdminLog::class]);
    })->middleware([\app\admin\middleware\AdminPermission::class]);

    //文章组
    Route::group('Article',function () {
        Route::rule('categoryIndex', 'admin/article.Category/index', 'get')->generateMenu([
            'parent_route' => 'admin/article', 'name' => 'category', 'title' => '文章分类', 'path' => '/category',
            'component' => 'view/article/category.vue', 'auth' => 0, 'sort' => 0, 'hide' => 0, 'icon' => '',
        ]);
        Route::rule('index', 'admin/article.Index/index', 'get')->generateMenu([
            'parent_route' => 'admin/article', 'name' => 'articles', 'title' => '文章列表', 'path' => '/articles',
            'component' => 'view/article/articles.vue', 'auth' => 0, 'sort' => 0, 'hide' => 0, 'icon' => '',
        ]);
        Route::group(function () {
            //分类
            Route::rule('categoryAdd', 'admin/article.Category/add', 'post')->generateMenu([ 'parent_route'=>'admin/article.Category/index', 'title'=>'添加文章分类' ]);
            Route::put('categoryEdit/:id', 'admin/article.Category/edit')->generateMenu([ 'parent_route'=>'admin/article.Category/index', 'title'=>'编辑文章分类' ]);
            Route::put('changeCategoryStatus/:id', 'admin/article.Category/changeStatus')->generateMenu([ 'parent_route'=>'admin/article.Category/index', 'title'=>'更新文章分类状态' ]);
            Route::delete('categoryDelete/:id', 'admin/article.Category/delete')->generateMenu([ 'parent_route'=>'admin/article.Category/index', 'title'=>'文章分类删除' ]);
            //文章
            Route::rule('add', 'admin/article.Index/add', 'post')->generateMenu([ 'parent_route'=>'admin/article.Index/index', 'title'=>'添加文章' ]);
            Route::put('edit/:id', 'admin/article.Index/edit')->generateMenu([ 'parent_route'=>'admin/article.Index/index', 'title'=>'编辑文章' ]);
            Route::put('changeStatus/:id', 'admin/article.Index/changeStatus')->generateMenu([ 'parent_route'=>'admin/article.Index/index', 'title'=>'更新状态' ]);
            Route::put('changeSort/:id', 'admin/article.Index/changeSort')->generateMenu([ 'parent_route'=>'admin/article.Index/index', 'title'=>'更新排序' ]);
            Route::put('changeTop/:id', 'admin/article.Index/changeTop')->generateMenu([ 'parent_route'=>'admin/article.Index/index', 'title'=>'更新置顶' ]);
            Route::put('changeRecommend/:id', 'admin/article.Index/changeRecommend')->generateMenu([ 'parent_route'=>'admin/article.Index/index', 'title'=>'更新推荐' ]);
            Route::delete('delete/:id', 'admin/article.Index/delete')->generateMenu([ 'parent_route'=>'admin/article.Index/index', 'title'=>'文章删除' ]);
        })->middleware([\app\admin\middleware\AdminLog::class]);
    });
    

    //配置组
    Route::group('Config', function () {
        Route::rule('index', 'admin/Config/index', 'get')->generateMenu([
            'parent_route'=>'admin/system', 'name'=>'config_setting', 'title'=>'平台配置', 'path'=>'config',
            'component'=>'view/system/config.vue', 'auth'=>0, 'sort'=>0, 'hide'=>0, 'icon'=>'',
        ]);
        Route::rule('check', 'admin/Config/check', 'get')->generateMenu([ 'parent_route'=>'admin/Config/index', 'title'=>'配置检查' ]);
        Route::group(function () {
            Route::rule('add', 'admin/Config/add', 'post')->generateMenu([ 'parent_route'=>'admin/Config/index', 'title'=>'配置添加' ]);
            Route::put('edit', 'admin/Config/edit')->generateMenu([ 'parent_route'=>'admin/Config/index', 'title'=>'配置编辑' ]);
            Route::delete('delete/:name', 'admin/Config/delete')->generateMenu([ 'parent_route'=>'admin/Config/index', 'title'=>'配置删除' ]);
            Route::rule('addGroup', 'admin/Config/addGroup', 'post')->generateMenu([ 'parent_route'=>'admin/Config/index', 'title'=>'配置分组添加' ]);
            Route::delete('delGroup/:name', 'admin/Config/delGroup')->generateMenu([ 'parent_route'=>'admin/Config/index', 'title'=>'配置分组删除' ]);
            Route::get('refreshFile', 'admin/Config/refreshFile')->generateMenu([ 'parent_route'=>'admin/Config/index', 'title'=>'配置刷新' ]);
        })->middleware([\app\admin\middleware\AdminLog::class]);
    })->middleware([\app\admin\middleware\AdminPermission::class]);

    //菜单组
    Route::group('Menu', function () {
        Route::rule('index', 'admin/Menu/index', 'get')->generateMenu([
            'parent_route'=>'admin/system', 'name'=>'menu_setting', 'title'=>'菜单维护', 'path'=>'menu',
            'component'=>'view/system/menu.vue', 'auth'=>0, 'sort'=>0, 'hide'=>0, 'icon'=>'',
        ]);
        Route::group(function () {
            Route::rule('generate', 'admin/Menu/generate', 'get')->generateMenu([ 'parent_route'=>'admin/Menu/index', 'title'=>'菜单一键生成' ]);
            Route::rule('add', 'admin/Menu/add', 'post')->generateMenu([ 'parent_route'=>'admin/Menu/index', 'title'=>'菜单添加' ]);
            Route::rule('edit', 'admin/Menu/edit', 'post')->generateMenu([ 'parent_route'=>'admin/Menu/index', 'title'=>'菜单编辑' ]);
            Route::rule('del', 'admin/Menu/del', 'get')->generateMenu([ 'parent_route'=>'admin/Menu/index', 'title'=>'菜单删除' ]);
            Route::rule('changeStatus', 'admin/Menu/changeStatus', 'get')->generateMenu([ 'parent_route'=>'admin/Menu/index', 'title'=>'菜单状态变更' ]);
        })->middleware([\app\admin\middleware\AdminLog::class]);
    })->middleware([\app\admin\middleware\AdminPermission::class]);

    //字典组
    Route::group('DataDict', function () {
        Route::rule('index', 'admin/DataDict/index', 'get')->generateMenu([
            'parent_route'=>'admin/system', 'name'=>'dict_setting', 'title'=>'数据字典', 'path'=>'data_dict',
            'component'=>'view/system/data_dict.vue', 'auth'=>0, 'sort'=>0, 'hide'=>0, 'icon'=>'',
        ]);
        Route::group(function () {
            Route::rule('add', 'admin/DataDict/add', 'post')->generateMenu([ 'parent_route'=>'admin/DataDict/index', 'title'=>'字典添加' ]);
            Route::rule('getDict', 'admin/DataDict/getDict', 'get')->generateMenu([ 'parent_route'=>'admin/DataDict/index', 'title'=>'获取字典' ]);
            Route::rule('edit', 'admin/DataDict/edit', 'put')->generateMenu([ 'parent_route'=>'admin/DataDict/index', 'title'=>'字典编辑' ]);
            Route::rule('delete/:id', 'admin/DataDict/delete', 'delete')->generateMenu([ 'parent_route'=>'admin/DataDict/index', 'title'=>'字典删除' ]);
            Route::rule('changeStatus/:id', 'admin/DataDict/changeStatus', 'put')->generateMenu([ 'parent_route'=>'admin/DataDict/index', 'title'=>'字典状态变更' ]);
        })->middleware([\app\admin\middleware\AdminLog::class]);
    })->middleware([\app\admin\middleware\AdminPermission::class]);

    //消息组
    Route::group('MessageLog', function () {
        Route::rule('index', 'admin/MessageLog/index', 'get')->generateMenu([
            'parent_route'=>'admin/system', 'name'=>'message_log', 'title'=>'消息管理', 'path'=>'message_log',
            'component'=>'view/system/message_log.vue', 'auth'=>0, 'sort'=>0, 'hide'=>0, 'icon'=>'',
        ]);
        Route::group(function () {
            Route::rule('add', 'admin/MessageLog/add', 'post')->generateMenu([ 'parent_route'=>'admin/MessageLog/index', 'title'=>'消息添加' ]);
            Route::rule('delete/:id', 'admin/MessageLog/delete', 'delete')->generateMenu([ 'parent_route'=>'admin/MessageLog/index', 'title'=>'消息删除' ]);
        })->middleware([\app\admin\middleware\AdminLog::class]);
    })->middleware([\app\admin\middleware\AdminPermission::class]);

    //日志组
    Route::group('Log', function () {
        Route::rule('index', 'admin/Log/index', 'get')->generateMenu([
            'parent_route'=>'admin/system', 'name'=>'logs', 'title'=>'日志管理', 'path'=>'logs',
            'component'=>'view/system/log.vue', 'auth'=>0, 'sort'=>0, 'hide'=>0, 'icon'=>'',
        ]);
        Route::group(function () {
            Route::rule('del', 'admin/Log/del', 'get')->generateMenu([ 'parent_route'=>'admin/Log/index', 'title'=>'删除单条日志记录' ]);
        })->middleware([\app\admin\middleware\AdminLog::class]);
    })->middleware([\app\admin\middleware\AdminPermission::class]);

    //授权组
    Route::group('Auth', function () {
        Route::rule('index', 'admin/Auth/index', 'get')->generateMenu([
            'parent_route'=>'admin/system', 'name'=>'auth_setting', 'title'=>'权限管理', 'path'=>'auth',
            'component'=>'view/system/auth.vue', 'auth'=>0, 'sort'=>0, 'hide'=>0, 'icon'=>'',
        ]);
        Route::group(function () {
            Route::rule('add', 'admin/Auth/add', 'post')->generateMenu([ 'parent_route'=>'admin/Auth/index', 'title'=>'授权添加' ]);
            Route::rule('edit', 'admin/Auth/edit', 'post')->generateMenu([ 'parent_route'=>'admin/Auth/index', 'title'=>'授权编辑' ]);
            Route::rule('del', 'admin/Auth/del', 'get')->generateMenu([ 'parent_route'=>'admin/Auth/index', 'title'=>'授权删除' ]);
            Route::rule('changeStatus', 'admin/Auth/changeStatus', 'get')->generateMenu([ 'parent_route'=>'admin/Auth/index', 'title'=>'授权状态变更' ]);
            Route::rule('delMember', 'admin/Auth/delMember', 'get')->generateMenu([ 'parent_route'=>'admin/Auth/index', 'title'=>'删除授权会员' ]);
            Route::rule('getGroups', 'admin/Auth/getGroups', 'get')->generateMenu([ 'parent_route'=>'admin/Auth/index', 'title'=>'获取授权分组' ]);
            Route::rule('getRuleList', 'admin/Auth/getRuleList', 'get')->generateMenu([ 'parent_route'=>'admin/Auth/index', 'title'=>'获取权限列表' ]);
        });
    })->middleware([\app\admin\middleware\AdminPermission::class]);

    //管理员组
    Route::group('User', function () {
        Route::rule('index', 'admin/User/index', 'get')->generateMenu([
            'parent_route'=>'admin/system', 'name'=>'user_setting', 'title'=>'后台用户', 'path'=>'user',
            'component'=>'view/system/user.vue', 'auth'=>0, 'sort'=>0, 'hide'=>0, 'icon'=>'',
        ]);
        Route::group(function () {
            Route::rule('add', 'admin/User/add', 'post')->generateMenu([ 'parent_route'=>'admin/User/index', 'title'=>'用户添加' ]);
            Route::rule('edit', 'admin/User/edit', 'post')->generateMenu([ 'parent_route'=>'admin/User/index', 'title'=>'用户编辑' ]);
            Route::rule('del', 'admin/User/del', 'get')->generateMenu([ 'parent_route'=>'admin/User/index', 'title'=>'用户删除' ]);
            Route::rule('changeStatus', 'admin/User/changeStatus', 'get')->generateMenu([ 'parent_route'=>'admin/User/index', 'title'=>'用户状态变更' ]);
            Route::rule('getUsers', 'admin/User/getUsers', 'get')->generateMenu([ 'parent_route'=>'admin/User/index', 'title'=>'获取当前组用户' ]);
            Route::rule('own', 'admin/User/own', 'post')->generateMenu([ 'parent_route'=>'admin/User/index', 'title'=>'更新个人信息' ]);
        })->middleware([\app\admin\middleware\AdminLog::class]);
    })->middleware([\app\admin\middleware\AdminPermission::class]);

    //前台用户组
    Route::group('FrontUser', function () {
        Route::rule('index', 'admin/user.Index/index', 'get')->generateMenu([
            'parent_route'=>'admin/user', 'name'=>'user_list', 'title'=>'用户列表', 'path'=>'users',
            'component'=>'view/user/index.vue', 'auth'=>0, 'sort'=>0, 'hide'=>0, 'icon'=>'',
        ]);
        Route::rule('real', 'admin/user.Index/real', 'get')->generateMenu([
            'parent_route'=>'admin/user', 'name'=>'user_real', 'title'=>'实名审核', 'path'=>'real',
            'component'=>'view/user/real.vue', 'auth'=>0, 'sort'=>0, 'hide'=>0, 'icon'=>'',
        ]);
        Route::group(function () {
            Route::rule('add', 'admin/user.Index/add', 'post')->generateMenu([ 'parent_route'=>'admin/user.Index/index', 'title'=>'添加会员' ]);
            Route::rule('edit/:id', 'admin/user.Index/edit', 'put')->generateMenu([ 'parent_route'=>'admin/user.Index/index', 'title'=>'编辑会员' ]);
            Route::rule('del/:id', 'admin/user.Index/del', 'delete')->generateMenu([ 'parent_route'=>'admin/user.Index/index', 'title'=>'删除会员' ]);
            Route::rule('changeStatus/:id', 'admin/user.Index/changeStatus', 'put')->generateMenu([ 'parent_route'=>'admin/user.Index/index', 'title'=>'变更会员状态' ]);
            Route::rule('checkReal/:id', 'admin/user.Index/checkReal', 'put')->generateMenu([ 'parent_route'=>'admin/user.Index/real', 'title'=>'审核会员实名' ]);
        })->middleware([\app\admin\middleware\AdminLog::class]);

    })->middleware([\app\admin\middleware\AdminPermission::class]);
})->middleware([\app\admin\middleware\AdminAuth::class]);

//MISS路由定义
Route::miss('admin/Miss/index');
